﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CE.iPhone.PList;
using cczEdit.DramaDialog;
namespace cczEdit.CommonInstructComposite
{
    public partial class UCCIUnitExit : UserControl,ICommonInstruct
    {
        public UCCIUnitExit()
        {
            InitializeComponent();
            foreach (Hero hero in UCDrama.heros)
            {
                
                comboBoxName.Items.Add(hero.name);
            }
            comboBoxName.SelectedIndex = 0;
        }
        public PListDict CreatResultDict()
        {
            Hero hero = UCDrama.heros.Find(h => h.name == comboBoxName.Text);
            if (hero == null)
            {
                MessageBox.Show("没有这个武将,请重试或尝试从下拉框选择");
                return null;
            }
            PListDict section = new PListDict();
            section.Add("Information", new PListString(hero.name+(checkBoxIsDead.Checked?"死亡":"撤退")));
            PListArray conditions = new PListArray();
            conditions.Add(CreateUnitExitTestDict(hero.num));
            PListDict varTestDict = AddDramaDialog.CreateConditionDict(kLogicalTestType.kLogicalTestTypeVariable);
            varTestDict["TrueVariables"] = new PListArray();
            PListArray falseVars = new PListArray();
            falseVars.Add(new PListInteger((long)numericUpDownVar.Value));
            varTestDict["FalseVariables"] = falseVars;
            conditions.Add(varTestDict);
            section.Add("Condition", conditions);
            PListArray dramas = new PListArray();
            dramas.Add(UCDrama.GetInstructDict(kInstructType.kInstructTypeDramaBegin));
            PListDict dialogDict = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeDialog);
            dialogDict["UnitID"] = new PListInteger(hero.num);
            dialogDict["Message"] = new PListString(textBoxWord.Text);
            dramas.Add(dialogDict);
            PListDict varSetDict = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeVariableSet);
            varSetDict["VariableIndex"]=new PListInteger((long)numericUpDownVar.Value);
            varSetDict["Value"] = new PListBool(true);
            dramas.Add(varSetDict);
            PListDict unitExitDict = AddDramaDialog.CreateInstructDict(kInstructType.kInstructTypeBattleExit);
            unitExitDict["DataType"] = new PListInteger(1);
            unitExitDict["IsDead"] = new PListBool(checkBoxIsDead.Checked);
            PListDict unitExitDictData = (PListDict)unitExitDict["Data"];
            unitExitDictData["UnitID"] = new PListInteger(hero.num);
            dramas.Add(unitExitDict);
            dramas.Add(UCDrama.GetInstructDict(kInstructType.kInstructTypeDramaOver));
            section.Add("Dramas", dramas);
            return section;
        }
        private PListDict CreateUnitExitTestDict(long unitID)
        {
            PListDict dict = AddDramaDialog.CreateConditionDict(kLogicalTestType.kLogicalTestTypeState);
            dict["UnitID"] = new PListInteger(unitID);
            dict["AttributeType"] = new PListInteger((long)kAttributeType.kAttributeTypeCurHP);
            dict["SymbolType"] = new PListInteger((long)kLogicalSymbolType.kLogicalSymbolTypeLessEqual);
            dict["Value"] = new PListInteger(0);
            return dict;
        }
        
    }
    
}
